/**
 * Created by Flower付成华 on 2018/5/15.
 */

var playstate = 0;//默认的播放类型， 0：单句，1：本课  2：复读
var audioHandler ;
var strs = [];
var curpindex = 0;
var curpagenum = 0;
var curobject;
var ispause = 0;//是否暂停
var curtime;//当前的 settimeout
var istranslation = false;
var curtrans = "";//当前选中的解释
var dicdata = {
    'classroom':'教室',
    'window':'窗户',
    'blackboard':'黑板',
    'light':'电灯',
    'picture':'图画',
    'door':'门',
    'teacher’s desk':'讲台',
    'computer':'计算机',
    'clean':'打扫'
};

var position_data = [
{
    page_data:[
        {
            text:'Unit 1 My classroom',
            translation:'第一单元 我的教室',
            duration:2,
            x:20.5,
            y:11.1,
            w:45.1,
            h:5.9
        },
        {
            text:'Unit 2 My schoolbag',
            translation:'第二单元 我的书包',
            duration:2,
            x:20.5,
            y:18.1,
            w:45.1,
            h:5.9
        },
        {
            text:'Unit 3 My friends',
            translation:'第三单元 我的朋友们',
            duration:2,
            x:20.5,
            y:24.5,
            w:40.2,
            h:5.9
        },
        {
            text:'Recycle 1',
            translation:'复习一',
            duration:2,
            x:20.5,
            y:31.0,
            w:24.3,
            h:5.9
        },
        {
            text:'Unit 4 My home',
            translation:'第四单元 我的家',
            duration:2,
            x:20.5,
            y:37.8,
            w:34.3,
            h:5.9
        },
        {
            text:'Unit 5 Dinner\'s ready',
            translation:'第五单元 晚餐准备好了',
            duration:2,
            x:20.5,
            y:45.1,
            w:48.8,
            h:5.9
        },
        {
            text:'Unit 6 Meet my family!',
            translation:'第六单元 认识一下我的家庭成员',
            duration:2,
            x:20.5,
            y:52.3,
            w:52.2,
            h:5.9
        },
        {
            text:'Recycle 2',
            translation:'复习二',
            duration:2,
            x:20.5,
            y:59.1,
            w:24.3,
            h:5.9
        },
        {
            text:'Words in each unit',
            translation:'附录一 单元词汇表',
            duration:2,
            x:20.5,
            y:65.7,
            w:43.3,
            h:5.9
        },
        {
            text:'Vocabulary',
            translation:'附录二 词汇表',
            duration:2,
            x:20.5,
            y:72.8,
            w:24.3,
            h:5.9
        },
        {
            text:'Useful expressions',
            translation:'附录三 常用表达法',
            duration:2,
            x:20.5,
            y:79.6,
            w:43.3,
            h:5.9
        }
    ]
}
,
{
    page_data:[
        {
            text:'ZhangPeng',
            translation:'张鹏',
            duration:2,
            w:266,
            h:267,
            x:123,
            y:170
        },
        {
            text:'Sarah',
            translation:'萨拉',
            duration:2,
            w:266,
            h:267,
            x:404,
            y:170
        },
        {
            text:'Miss White',
            translation:'怀特小姐',
            duration:2,
            x:692,
            y:169,
            w:266,
            h:267
        },
        {
            text:'Wuyifan',
            translation:'吴一凡',
            duration:2,
            x:123,
            y:462,
            w:266,
            h:267
        },
        {
            text:'ChenJie',
            translation:'陈杰',
            duration:2,
            x:404,
            y:462,
            w:266,
            h:267
        },
        {
            text:'Mike',
            translation:'麦克',
            duration:2,
            x:692,
            y:462,
            w:266,
            h:267
        },
        {
            text:'MrJones',
            translation:'琼斯先生',
            duration:2,
            x:122,
            y:759,
            w:254,
            h:249
        },
        {
            text:'John',
            translation:'约翰',
            duration:2,
            x:414,
            y:759,
            w:254,
            h:249
        },
        {
            text:'Amy',
            translation:'埃米',
            duration:2,
            x:706,
            y:764,
            w:254,
            h:249
        },
        {
            text:'Zoom',
            translation:'佐姆',
            duration:2,
            x:222,
            y:1009,
            w:263,
            h:171
        },
        {
            text:'Zip',
            translation:'齐普',
            duration:2,
            x:629,
            y:1080,
            w:263,
            h:171
        }
        

    ]
},
{
    page_data:[
        {
            text:'Unit One',
            translation:'第一单元',
            duration:3,
            x:296,
            y:137,
            w:344,
            h:84
        },
        {
            text:'Where\'s my schoolbag?',
            translation:'我的书包在哪里？',
            duration:3,
            x:265,
            y:380,
            w:323,
            h:76
        },
        {
            text:'It\'s near the computer.',
            translation:'就在电脑旁边。',
            duration:3,
            x:552,
            y:560,
            w:328,
            h:75
        },
        {
            text:'Let\'s clean the desks and chairs.',
            translation:'我们擦擦书桌和椅子吧。',
            duration:3,
            x:222,
            y:633,
            w:263,
            h:108
        },
        {
            text:'Let me clean the windows.',
            translation:'我来擦窗户。',
            duration:3,
            x:260,
            y:1016,
            w:357,
            h:76
        }

    ]
},
{
    page_data:[
        {
            text:'My classroom',
            translation:'我的教室',
            duration:3,
            x:246,
            y:141,
            w:491,
            h:76
        },
        {
            text:'Hey,ZhangPeng We have a new classroom.',
            translation:'你好张鹏，我们有一间新教室。',
            duration:3,
            x:575,
            y:226,
            w:315,
            h:112
        },
        {
            text:'Let me clean the fish bowl.',
            translation:'我来擦鱼缸。',
            duration:3,
            x:192,
            y:511,
            w:363,
            h:78
        },
        {
            text:'Excuse me.',
            translation:'劳驾！',
            duration:3,
            x:460,
            y:747,
            w:183,
            h:73
        },
        {
            text:'Oh, sorry.',
            translation:'噢，对不起。',
            duration:3,
            x:601,
            y:913,
            w:184,
            h:74
        }

    ]
},
{
    page_data:[
        {
            text:'Let\'s talk',
            translation:'A 让我们来学对话吧。',
            duration:3,
            x:177,
            y:129,
            w:297,
            h:53
        },
        {
            text:'Hey,ZhangPeng.We have a new classroom.',
            translation:'你好张鹏，我们有一间新教室。',
            duration:3,
            x:92,
            y:227,
            w:359,
            h:109
        },
        {
            text:'Really? What\'s in the classroom?',
            translation:'真的？教室里有什么？',
            duration:3,
            x:176,
            y:340,
            w:298,
            h:100
        },
        {
            text:'Let\'s go and see!',
            translation:'我们去看看吧。',
            duration:3,
            x:82,
            y:445,
            w:267,
            h:84
        },
        {
            text:'It\'s so big!',
            translation:'真大呀！',
            duration:3,
            x:536,
            y:214,
            w:197,
            h:78
        },
        {
            text:'Look! My picture!',
            translation:'看！我的画！',
            duration:3,
            x:614,
            y:296,
            w:262,
            h:73
        },
        {
            text:'Where is it?',
            translation:'它在哪儿？',
            duration:3,
            x:537,
            y:371,
            w:206,
            h:78
        },
        {
            text:'It\'s near the window.',
            translation:'就在窗户旁边。',
            duration:3,
            x:580,
            y:458,
            w:298,
            h:74
        },
        {
            text:'Let\'s play',
            translation:'让我们来玩一玩吧',
            duration:3,
            x:177,
            y:771,
            w:275,
            h:65
        },
        {
            text:'I see a "c".',
            translation:'我看见一个“c”。',
            duration:3,
            x:135,
            y:841,
            w:184,
            h:88
        },
        {
            text:'Where is it?',
            translation:'它在哪儿？',
            duration:3,
            x:337,
            y:901,
            w:206,
            h:84
        },
        {
            text:'It\'s in a desk.',
            translation:'它在书桌里。',
            duration:3,
            x:120,
            y:956,
            w:204,
            h:85
        },
        {
            text:'It\'s a crayon.',
            translation:'它是支蜡笔。',
            duration:3,
            x:339,
            y:1180,
            w:215,
            h:82
        }

    ]
}
,
{
    page_data:[
        {
            text:'Let\'s learn',
            translation:'让我们来学一学吧。',
            duration:3,
            x:218,
            y:127,
            w:328,
            h:55
        },
        {
            text:'classroom',
            translation:'教室',
            duration:3,
            x:137,
            y:286,
            w:138,
            h:33
        },
        {
            text:'window',
            translation:'窗户',
            duration:3,
            x:231,
            y:492,
            w:109,
            h:34
        },
        {
            text:'blackboard',
            translation:'黑板',
            duration:3,
            x:390,
            y:295,
            w:159,
            h:35
        },
        {
            text:'light',
            translation:'电灯',
            duration:3,
            x:638,
            y:135,
            w:83,
            h:34
        },
        {
            text:'pricture',
            translation:'图画',
            duration:3,
            x:768,
            y:123,
            w:111,
            h:31
        },
        {
            text:'door',
            translation:'门',
            duration:3,
            x:852,
            y:240,
            w:87,
            h:48
        },
        {
            text:'What\'s in the classroom?',
            translation:'教室里有什么？',
            duration:3,
            x:375,
            y:459,
            w:363,
            h:87
        },
        {
            text:'One blackboard,on TV,many desks and chairs...',
            translation:'一块黑板，一台电视机，许多书桌和椅子。',
            duration:3,
            x:503,
            y:635,
            w:369,
            h:128
        },
        {
            text:'Let\'s do',
            translation:'让我们来做一做吧',
            duration:3,
            x:227,
            y:775,
            w:254,
            h:69
        },
        {
            text:'Open the door.',
            translation:'开门',
            duration:3,
            x:188,
            y:880,
            w:213,
            h:54
        },
        {
            text:'Turn on the light',
            translation:'开灯',
            duration:3,
            x:533,
            y:959,
            w:238,
            h:53
        },
        {
            text:'Close the window.',
            translation:'关窗',
            duration:3,
            x:177,
            y:1040,
            w:250,
            h:57
        },
        {
            text:'Put up the picture.',
            translation:'贴图画',
            duration:3,
            x:519,
            y:1127,
            w:259,
            h:52
        },
        {
            text:'Clean the blackboard.',
            translation:'檫黑板',
            duration:3,
            x:180,
            y:1211,
            w:294,
            h:53
        }

    ]
}
];



//判断手机类型
window.onload = function () {
    //初始化audio
    initAudio();
    
    //alert($(window).height());
    var u = navigator.userAgent;
    if (u.indexOf('Android') > -1 || u.indexOf('Linux') > -1) {//安卓手机
    } else if (u.indexOf('iPhone') > -1) {//苹果手机
        //屏蔽ios下上下弹性
        $(window).on('scroll.elasticity', function (e) {
            e.preventDefault();
        }).on('touchmove.elasticity', function (e) {
            e.preventDefault();
        });
    } else if (u.indexOf('Windows Phone') > -1) {//winphone手机
    }
    //预加载
    loading();
}

var date_start;
var date_end;
date_start = getNowFormatDate();
//加载图片
var loading_img_url = [
    "../img/en_book_1.png",
    "../img/en_book_2.png",
    "../img/en_book_3.png",
    "../img/en_book_4.png",
    "../img/en_book_5.png",
    "../img/en_book_6.png"
];

//加载页面
function loading() {
    var numbers = 0;
    var length = loading_img_url.length;
    
    for (var i = 0; i < length; i++) {
        var img = new Image();
        img.src = loading_img_url[i];
        img.onerror = function () {
            numbers += (1 / length) * 100;
        }
        img.onload = function () {
            numbers += (1 / length) * 100;
            $('.number').html(parseInt(numbers) + "%");
            console.log("number:"+numbers);
            if (Math.round(numbers) == 100) {
                //$('.number').hide();
                date_end = getNowFormatDate();
                var loading_time = date_end - date_start;
                //预加载图片
                $(function progressbar() {
                    //拼接图片
                    $('.shade').hide();
                    var tagHtml = "";
                    for (var i = 1; i <= position_data.length; i++) {
                        if (i == 1) {
                            // tagHtml += ' <div id="first" style="background:url(../img/en_book_' + i + '.png) center top no-repeat;background-size:100%"></div>';
                            tagHtml += " <img id='first' src='../img/en_book_" + i + ".png' />";
                        } else if (i == position_data.length) {
                            // tagHtml += ' <div id="end" style="background:url(../img/en_book_' + i + '.png) center top no-repeat;background-size:100%"></div>';
                            tagHtml += " <img id='end' src='../img/en_book_" + i + ".png' />";
                        } else {
                            // tagHtml += ' <div style="background:url(../img/en_book_' + i + '.png) center top no-repeat;background-size:100%"></div>';
                            tagHtml += " <img  src='../img/en_book_" + i + ".png' />";
                        }
                    }
                    $(".flipbook").append(tagHtml);
                    var w = $(".graph").width();
                    $(".flipbook-viewport").show();
                });
                //配置turn.js
                function loadApp() {
                    var w = $(window).width();
                    var h = $(window).height();
                    $('.flipboox').width(w).height(h);
                    $(window).resize(function () {
                        w = $(window).width();
                        h = $(window).height();
                        $('.flipboox').width(w).height(h);
                    });
                    $('.flipbook').turn({
                        // Width
                        width: w,
                        // Height
                        height: h,
                        // Elevation
                        elevation: 50,
                        display: 'single',
                        // Enable gradients
                        gradients: false,
                        // Auto center this flipbook
                        autoCenter: true,
                        when: {
                            turning: function (e, page, view) {
                                
                                ispause = 1;
                                audioHandler.pause();
                                $("#bottom_menu_img2").attr("src","../img/icon_play.png");
                                
                                // if (page == 1) {
                                //     $(".btnImg").css("display", "none");
                                //     $(".mark").css("display", "block");
                                // } else {
                                //     $(".btnImg").css("display", "block");
                                //     $(".mark").css("display", "none");
                                // }
                                // if (page == 6) {
                                //     $(".nextPage").css("display", "none");
                                // } else {
                                //     $(".nextPage").css("display", "block");
                                // }
                            },
                            turned: function (e, page, view) {
                                console.log(page);
                                var total = $(".flipbook").turn("pages");//总页数
                                $("#div_container div").css('border','0px solid white');
                                // if (page == 1) {
                                //     $(".return").css("display", "none");
                                //     $(".btnImg").css("display", "none");
                                // } else {
                                //     $(".return").css("display", "block");
                                //     $(".btnImg").css("display", "block");
                                // }
                                // if (page == 2) {
                                //     $(".catalog").css("display", "block");
                                // } else {
                                //     $(".catalog").css("display", "none");
                                // }
                                // $("#idv_container").css("display","bla");
                                //动态创建btn
                                createCheckImage(page);
                            }
                        }
                    })
                }
                yepnope({
                    test: Modernizr.csstransforms,
                    yep: ['../js/turn.js'],
                    complete: loadApp
                });
            }
            ;
        }
    }
}

function getNowFormatDate() {
    var date = new Date();
    var seperator1 = "";
    var seperator2 = "";
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
        + "" + date.getHours() + seperator2 + date.getMinutes()
        + seperator2 + date.getSeconds();
    return currentdate;
}


function createCheckImage(pindex){
    console.log(pindex);
    if(position_data.length>0){
        for(var i = 0;i<position_data.length;i++){
            var pages = position_data[i].page_data;
            if(pindex-1 == i){
                if(pages.length>0){

                    var imgContainer=document.getElementById("div_container");
                    $("#div_container").html("");
                    for (var j = 0; j<pages.length; j++) {
                        var x = pages[j].x;
                        var y = pages[j].y;
                        var w = pages[j].w;
                        var h = pages[j].h;
                        var duration = pages[j].duration;
                        var translationtips = pages[j].translation;
                        var curtext = pages[j].text;
                                var cid;
                                var div;
                                if(pindex==1){
                                    imgContainer.style.height=100+"%";
                                    div = document.createElement("div");
                                    var aa = Number(i)+1;
                                    var bb = Number(j)+1;
                                    cid = aa+"_"+bb + "_"+Number(duration);
                                    div.id =cid;
                                    div.title = translationtips+"0_0!!"+curtext;
                                    div.style.width = w+"%";
                                    div.style.height = h+"%";
                                    div.style.border = "1px solid #0099FF";
                                    div.style.borderRadius = 5+'px';
                                    // div.style.position="absolute";
                                    div.style.left=x+"%";
                                    div.style.zIndex = "100";
                                    div.style.position = "absolute";
                                    div.style.top=(y+(y/10))+"%";
                                    // div.style.backgroundColor="green";
                                    imgContainer.appendChild(div);
                                }else{
                                    imgContainer.style.height=100+"%";
                                    div = document.createElement("div");
                                    var aa = Number(i)+1;
                                    var bb = Number(j)+1;
                                    cid = aa+"_"+bb + "_"+Number(duration);
                                    div.id =cid;
                                    div.title = translationtips+"0_0!!"+curtext;
                                    div.style.width = (w/1024)*100+"%";
                                    div.style.height = (h/1431)*100+"%";
                                    div.style.border = "1px solid #0099FF";
                                    // div.style.position="absolute";
                                    div.style.borderRadius = 5+'px';
                                    div.style.left=(x/1024)*100+"%";
                                    div.style.zIndex = "100";
                                    div.style.position = "absolute";
                                    div.style.top=(y/(1431-(1431/10)))*100+"%";
                                    // div.style.backgroundColor="green";
                                    imgContainer.appendChild(div);
                                    console.log(div.style.width);
                                }
                                
                                div.onclick=function(){
                                    if(playstate == 4){//查词功能，点击弹出内容弹窗，选择复制查词
                                        searchWords(this);
                                        return;
                                    }



                                    read(this,pindex,pages.length);

                                };

                    }

                    return;
                }    
            }
            
        }
    }
    

}



//初始化audio
function initAudio(){

    var curalltime = 5;
    audioHandler = new AudioPlayer({
       id: 'music_player'
    });

    audioHandler.on('canplay', function (totalTime, name, item) {
        audioHandler.play();
        console.log('canplay');
        curalltime = totalTime;
    });

    audioHandler.on('play' , function (){
        console.log('play');

        curtime = setTimeout(function(){

         if(playstate == 0){
             $("#bottom_menu_img2").attr("src","../img/icon_play.png");
             $("#div_tips").hide();

         }else if(playstate == 1){//全局阅读

             if(strs[1]>=curpagenum || ispause){
                audioHandler.pause();
                 $("#bottom_menu_img2").attr("src","../img/icon_play.png");
                 $("#div_tips").hide();

             }else{

                 var ccid = strs[0]+"_"+(Number(strs[1])+1)+"_"+Number(strs[2]);
                 read($("#"+ccid),curpindex,curpagenum);    
             }

         }else if(playstate == 2){//循环阅读

            if(ispause){
                
            }else{
                audioHandler.pause();
                read(curobject,curpindex,curpagenum);
            }
         }else if(playstate == 3){//连续

         }else if(playstate == 4){//查词
            

         }
          
        },curalltime*1200)
    });

}




//开始阅读
function read(ob,pindex,pagenum){
    
    //全局
    curpagenum = pagenum;
    curpindex = pindex;
    curobject = ob;

    $("#div_container div").css('border','0px solid white');
    $(ob).css('border','1px solid #0099FF');
    var strid = $(ob).attr("id")+"";
    var str_tips_arr = $(ob).attr("title")+"";
    var tips_arr = str_tips_arr.split("0_0!!");
    var tips = tips_arr[0];
    console.log('id:'+strid);
    strs = strid.split("_");
    var msrc = "https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/sound/"+(strs[0])+"_"+(strs[1])+".mp3";
     // $("#bgmusic").get(0).pause();
     $("#bottom_menu_img2").attr("src","../img/icon_unplay.png");

     $("#div_tips").hide();
     $("#div_tips").html(tips);
     if(istranslation){
        $("#div_tips").show();   
     }
     
     var list = [{
        name: strid,
        url: msrc,
        time: strs[2]
    }];

    //播放声音
    // $("#bgmusic").html("<source src="+msrc+">");
    // $("#bgmusic").get(0).load();

    ispause = 0;
    clearTimeout(curtime);
    audioHandler.clearList();
    audioHandler.add(list);
    audioHandler.loadIndex(0);
    
  /* $("#bgmusic").get(0).oncanplay = function () {  
           // sounds = $("#bgmusic").get(0).duration;     
           $("#bgmusic").get(0).play();
           setTimeout(function(){

            if(playstate == 0){
                $("#bottom_menu_img2").attr("src","../img/icon_play.png");

            }else if(playstate == 1){//全局阅读

                if(strs[1]>=pagenum){
                    $("#bottom_menu_img2").attr("src","../img/icon_play.png");
                }else{

                    var ccid = strs[0]+"_"+(Number(strs[1])+1);
                    read($("#"+ccid),pindex,pagenum);    
                }
                

            }else if(playstate == 2){//循环阅读

                if($("#bgmusic").get(0).paused){

                }else{
                    read(ob,pindex,pagenum);
                }
                

            }
             
           },sounds*1000)
     }*/

}


function showmenu(){

    toshare();
}


//点击改变播放音频的状态
function readstate(){

   /* if($("#bgmusic").get(0).paused){//暂停
        $("#bgmusic").get(0).play();
        
        $("#bottom_menu_img2").attr("src","../img/icon_unplay.png");
    }else{
        $("#bgmusic").get(0).pause();
        $("#bottom_menu_img2").attr("src","../img/icon_play.png");
    }*/

    if(audioHandler.playing){//暂停
        ispause = 1;
        audioHandler.pause();
        $("#bottom_menu_img2").attr("src","../img/icon_play.png");
    }else{
        ispause = 0;
        audioHandler.play();
        $("#bottom_menu_img2").attr("src","../img/icon_unplay.png");
        
    }
}


//弹出层
function toshare(){
        $(".am-share").addClass("am-modal-active"); 
        if($(".sharebg").length>0){
            $(".sharebg").addClass("sharebg-active");
        }else{
            $("body").append('<div class="sharebg"></div>');
            $(".sharebg").addClass("sharebg-active");
        }
        $(".sharebg-active,.share_btn").click(function(){
            $(".am-share").removeClass("am-modal-active");  
            setTimeout(function(){
                $(".sharebg-active").removeClass("sharebg-active"); 
                $(".sharebg").remove(); 
            },300);
        })
} 

function menu1(){
    $("#li_menu4").css("background-image","url(../img/icon_menu1_off.png)");
    $("#li_menu5").css("background-image","url(../img/icon_menu2_off.png)");
    $("#li_menu6").css("background-image","url(../img/icon_menu3_off.png)");
    $("#li_menu7").css("background-image","url(../img/icon_menu4_off.png)");
    $("#li_menu8").css("background-image","url(../img/icon_menu5_off.png)");
    
    $("#li_menu4").css("background-image","url(../img/icon_menu1_on.png)");
    $(".am-share").removeClass("am-modal-active");  
            setTimeout(function(){
                $(".sharebg-active").removeClass("sharebg-active"); 
                $(".sharebg").remove(); 
            },300);
    playstate = 0;
}  

function menu2(){
    $("#li_menu4").css("background-image","url(../img/icon_menu1_off.png)");
    $("#li_menu5").css("background-image","url(../img/icon_menu2_off.png)");
    $("#li_menu6").css("background-image","url(../img/icon_menu3_off.png)");
    $("#li_menu7").css("background-image","url(../img/icon_menu4_off.png)");
    $("#li_menu8").css("background-image","url(../img/icon_menu5_off.png)");


    $("#li_menu5").css("background-image","url(../img/icon_menu2_on.png)");
    $(".am-share").removeClass("am-modal-active");  
            setTimeout(function(){
                $(".sharebg-active").removeClass("sharebg-active"); 
                $(".sharebg").remove(); 
            },300);

            playstate = 1;
} 

 function menu3(){
    $("#li_menu4").css("background-image","url(../img/icon_menu1_off.png)");
    $("#li_menu5").css("background-image","url(../img/icon_menu2_off.png)");
    $("#li_menu6").css("background-image","url(../img/icon_menu3_off.png)");
    $("#li_menu7").css("background-image","url(../img/icon_menu4_off.png)");
    $("#li_menu8").css("background-image","url(../img/icon_menu5_off.png)");


    $("#li_menu6").css("background-image","url(../img/icon_menu3_on.png)");
    $(".am-share").removeClass("am-modal-active");  
            setTimeout(function(){
                $(".sharebg-active").removeClass("sharebg-active"); 
                $(".sharebg").remove(); 
            },300);

            playstate = 2;
} 


function menu4(){
    $("#li_menu4").css("background-image","url(../img/icon_menu1_off.png)");
    $("#li_menu5").css("background-image","url(../img/icon_menu2_off.png)");
    $("#li_menu6").css("background-image","url(../img/icon_menu3_off.png)");
    $("#li_menu7").css("background-image","url(../img/icon_menu4_off.png)");
    $("#li_menu8").css("background-image","url(../img/icon_menu5_off.png)");


    $("#li_menu7").css("background-image","url(../img/icon_menu4_on.png)");
    $(".am-share").removeClass("am-modal-active");  
            setTimeout(function(){
                $(".sharebg-active").removeClass("sharebg-active"); 
                $(".sharebg").remove(); 
            },300);

            playstate = 1;
}

function menu5(){
    $("#li_menu4").css("background-image","url(../img/icon_menu1_off.png)");
    $("#li_menu5").css("background-image","url(../img/icon_menu2_off.png)");
    $("#li_menu6").css("background-image","url(../img/icon_menu3_off.png)");
    $("#li_menu7").css("background-image","url(../img/icon_menu4_off.png)");
    $("#li_menu8").css("background-image","url(../img/icon_menu5_off.png)");


    $("#li_menu8").css("background-image","url(../img/icon_menu5_on.png)");

    $(".am-share").removeClass("am-modal-active");  
            setTimeout(function(){
                $(".sharebg-active").removeClass("sharebg-active"); 
                $(".sharebg").remove(); 
            },300);

            playstate = 4;
}


//开始点击查词,弹出框框
function searchWords(ob){

    var str_tips_arr = $(ob).attr("title")+"";
    var tips_arr = str_tips_arr.split("0_0!!");
    var text = tips_arr[1];
    curtrans = tips_arr[0];
    $("#div_words_dialog_content").html(text);
    $("#div_words_dialog").show();
    $("#div_words_bg").show();
}

//关闭弹窗
function closeDialog(){
    $("#div_words_dialog").hide();
    $("#div_words_bg").hide();
}

//获取选中的文本，执行查词功能
function getCurText(){

    var text = window.getSelection().toString();

    if((Object.keys(dicdata)).indexOf(text) == -1){
        //开始弹出查词的框
        alert("查词解释：  暂无此解释");
    }else{
        //开始弹出查词的框
        alert("查词解释：  "+text+": "+dicdata[text]);
    }
    

}

// http://dict-co.iciba.com/api/dictionary.php?w=go&key=DE5EB7C205E95AB2884CB14102E64369&type=json
//是否需要翻译提示
function translation_change(){
    if(istranslation){
        $("#bottom_menu_img3").attr('src', '../img/img_translation_off.png'); 
        istranslation = false;
    }else{
        $("#bottom_menu_img3").attr('src', '../img/img_translation_on.png'); 
        istranslation = true;
    }
}
